﻿Imports System.Web.UI

Namespace Controls
    <PersistenceMode(PersistenceMode.InnerProperty)> _
    Public NotInheritable Class TabPageCollection
        Inherits CollectionBase
        Implements IList

        Private _tabControl As TabControl

        Friend Sub New(ByVal i_tabControl As TabControl)
            Me._tabControl = i_tabControl
        End Sub

        Public Sub Add(ByVal pTab As TabPage)
            MyBase.List.Add(pTab)
        End Sub

        Public Function Contains(ByVal pTab As TabPage) As Boolean
            Return MyBase.List.Contains(pTab)
        End Function

        Public Sub CopyTo(ByVal pArray As TabPage(), ByVal pIndex As Integer)
            MyBase.List.CopyTo(pArray, pIndex)
        End Sub

        Public Function IndexOf(ByVal pItem As TabPage) As Integer
            Return MyBase.List.IndexOf(pItem)
        End Function

        Public Sub Insert(ByVal pIndex As Integer, ByVal pItem As TabPage)
            MyBase.List.Insert(pIndex, pItem)
        End Sub


        Protected Overloads Overrides Sub OnInsert(ByVal index As Integer, ByVal value As Object)
            If value.[GetType]() IsNot Type.[GetType]("LSW.Web.Controls.TabPage") Then
                Throw New ArgumentException("插入的子项类型必须为 [TabPage]")
            End If
        End Sub

        Protected Overloads Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal value As Object)
            If value.[GetType]() Is Type.[GetType]("LSW.Web.Controls.TabPage") Then
                DirectCast(value, TabPage).SetTabControl(Me._tabControl)
            End If
        End Sub

        Protected Overloads Overrides Sub OnRemove(ByVal index As Integer, ByVal value As Object)
            If value.[GetType]() IsNot Type.[GetType]("LSW.Web.Controls.TabPage") Then
                Throw New ArgumentException("移除的子项类型必须为 [TabPage]")
            End If
        End Sub

        Protected Overloads Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue As Object, ByVal newValue As Object)
            If newValue.[GetType]() IsNot Type.[GetType]("LSW.Web.Controls.TabPage") Then
                Throw New ArgumentException("类型必须为 [TabPage]")
            End If
        End Sub

        Protected Overloads Overrides Sub OnValidate(ByVal value As Object)
            If value.[GetType]() IsNot Type.[GetType]("LSW.Web.Controls.TabPage") Then
                Throw New ArgumentException("类型必须为 [TabPage]")
            End If
        End Sub


        Public Sub Remove(ByVal pTab As TabPage)
            MyBase.List.Remove(pTab)
        End Sub


        Default Public Property Item(ByVal index As Integer) As TabPage
            Get
                Return DirectCast(MyBase.List(index), TabPage)
            End Get
            Set(ByVal value As TabPage)
                MyBase.List(index) = value
            End Set
        End Property

    End Class
End Namespace
